package com.liang.paul.officelite.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.liang.paul.officelite.R;
import com.liang.paul.officelite.beams.TaskBeam;
import com.liang.paul.officelite.holders.TaskHolder;

import java.util.ArrayList;

/**
 * Created by paulliang on 16/5/30.
 */
public class TaskAdapter extends BaseAdapter {

    ArrayList<TaskBeam> datas;
    Context context;

    public TaskAdapter(ArrayList<TaskBeam> datas, Context context) {
        this.datas = datas;
        this.context = context;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TaskHolder holder;
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.list_task, null);
            holder = new TaskHolder(
                    (TextView) convertView.findViewById(R.id.txt_tasklist_name),
                    (TextView) convertView.findViewById(R.id.txt_tasklist_create),
                    (TextView) convertView.findViewById(R.id.txt_tasklist_ddl));
            convertView.setTag(holder);
        }else {
            holder = (TaskHolder) convertView.getTag();
        }
        holder.setName(datas.get(position).getTitle());
        holder.setStart(datas.get(position).getCreatedAt());
        holder.setStop(datas.get(position).getDDLDay() + " "
                + datas.get(position).getDDLTime());
        return convertView;
    }
}
